package com.augurit.gzcgwsp.csshlj.convert;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;
import org.springframework.beans.factory.annotation.Autowired;

import com.augurit.gzcgwsp.csshlj.entity.ShljqsBa;
import com.augurit.gzcgwsp.csshlj.form.ShljqsBaForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.gzcgwsp.smartformCsdlwj.service.ISmartFormShljqsService;
import com.augurit.gzcgwsp.smartformCsdlwj.web.form.ShljqsForm;



public class ShljqsBaConvertor {
	@Autowired
	private ISmartFormShljqsService smartFormShljqsService;
	
    public static ShljqsBaForm convertVoToForm(ShljqsBa entity ,ShljqsForm qsForm) {
        if (entity == null) return null;
        ShljqsBaForm form = new ShljqsBaForm();
        new DozerBeanMapper().map(qsForm, form);
        form.setId(entity.getId());
        form.setAcceptNo(entity.getAcceptNo());
        form.setAcceptNo2(entity.getAcceptNo());
        form.setYsid(entity.getYsid());
        form.setSqrq(entity.getSqrq());
        return form;
    }
    
    
    public static void convertFormToVo(ShljqsBaForm form, ShljqsBa entity) {
        if (form == null) return;
        if (entity == null) entity = new ShljqsBa();
        
        new DozerBeanMapper().map(form, entity);
    }
    
    public List<ShljqsBaForm> convertVoListToFormList(List<ShljqsBa> ShljqsBaList) {
        if(ShljqsBaList != null && ShljqsBaList.size() > 0) {
            List<ShljqsBaForm> shljqsBaFormList = new ArrayList();
            for(int i=0; i<ShljqsBaList.size(); i++) {
            	if(ShljqsBaList.get(i).getYsid() !=null){
            		ShljqsForm qsForm =	smartFormShljqsService.getForm(ShljqsBaList.get(i).getYsid(),  "hw_shljqs_v1");
                	shljqsBaFormList.add(convertVoToForm(ShljqsBaList.get(i),qsForm));
            	}
            	
            }
            return shljqsBaFormList;
        }
        return null;
    }
    
    public static List<ShljqsBa> convertFormListToVoList(List<ShljqsBaForm> ShljqsBaFormList) {
        if(ShljqsBaFormList != null && ShljqsBaFormList.size() > 0) {
            List<ShljqsBa> shljqsBaList = new ArrayList();
            for(int i=0; i<ShljqsBaFormList.size(); i++) {
                ShljqsBa shljqsBa = new ShljqsBa();
                convertFormToVo(ShljqsBaFormList.get(i), shljqsBa);
                shljqsBaList.add(shljqsBa);
            }
            return shljqsBaList;
        }
        return null;
    }
}